﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.Unity;
using SISLOG.BusinessLogic;
using SISLOG.BusinessEntities;

namespace SISLOG.Web
{
    public partial class RealizarOrdenPedido : BasePage<RealizarOrdenPedido>//System.Web.UI.Page
    {
        [Dependency]
        public IMaterialBL MaterialBL { get; set; }

        private const string VARMATERIAL = "material";

        protected void Page_Load(object sender, EventArgs e)
        {
            GridView1.DataSource = MaterialBL.GetAllFromMaterial();
            GridView1.DataBind();
        }

        protected void botonBuscar_Click(object sender, EventArgs e)
        {
            List<Material> listaMaterial = new List<Material>();

            if (RadioButton1.Checked)
            {
                listaMaterial = MaterialBL.GetAllFromMaterialByCriterio(txtCriterio.Text);
            }
            else
            {
                listaMaterial = MaterialBL.GetAllFromMaterialByProveedor(txtCriterio.Text);
            }

            GridView1.DataSource = listaMaterial;//para cargar los datos en la grilla
            GridView1.DataBind();//mostrar los datos de la grilla
            ModalPopupExtender1.Show();
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ModalPopupExtender1.Show();

            var idMaterial = Int32.Parse(GridView1.SelectedValue.ToString());
            var material = MaterialBL.GetAllFromMaterialByIdMaterial(idMaterial);

            txtDescripcion.Text = material.descripcion;
            //txtIdMaterial..Text = material.idMaterial;
            //txtCantidad.Text = "1";

            Cache.Insert(VARMATERIAL, material);
        }

        protected void btnCancelar_Click(object sender, EventArgs e)
        {
            Response.Redirect("RealizarOrdenPedido.aspx");
        }
    }
}